﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Data;
using MultiPanelTest.Data;

namespace MultiPanelTest
{
    /// <summary>
    /// Model class
    /// </summary>
    public class Products
    {
        private IEnumerable<Product> productList;
        DataProvider provider;
   
        public Products()
        {
            // Instantiate dataset
            this.provider = new DataProvider();
            //ProductsTableAdapter adapter = new ProductsTableAdapter();
            // Populate products table
            //adapter.Fill(dataSet.Products);            
        }

        public void PopulateList()
        {
            productList = this.provider.GetProducts().ToList<Product>();
        }

        public void FilterData(string filter)
        {
            if (filter != "")
            {
                IEnumerable<Product> result = this.provider.GetProducts().Where<Product>
                    (s => s.ProductName.ToLower().StartsWith(filter.ToLower()));
                this.productList = result;
            }
            else
            {
                PopulateList();                
            }           
        }

        public IEnumerable<Product> ProductList
        {
            get
            {
                return productList;
            }
        }
       
    }

}
